import mongoose, { Document, Schema } from 'mongoose'

export interface IGift extends Document {
  name: string
  description: string
  price: number
  icon: string
  animation: {
    type: string
    url: string
    duration: number
    scale: number
    sound: string
  }
  category: 'normal' | 'special' | 'limited'
  available: boolean
  startTime?: Date
  endTime?: Date
  createdAt: Date
}

const GiftSchema = new Schema({
  name: {
    type: String,
    required: true,
    unique: true,
  },
  description: {
    type: String,
    required: true,
  },
  price: {
    type: Number,
    required: true,
    min: 0,
  },
  icon: {
    type: String,
    required: true,
  },
  animation: {
    type: {
      type: String,
      enum: ['simple', 'advanced', 'special'],
      default: 'simple',
    },
    url: {
      type: String,
      required: true,
    },
    duration: {
      type: Number,
      default: 3000, // 3秒
    },
    scale: {
      type: Number,
      default: 1,
    },
    sound: String,
  },
  category: {
    type: String,
    enum: ['normal', 'special', 'limited'],
    default: 'normal',
  },
  available: {
    type: Boolean,
    default: true,
  },
  startTime: Date,
  endTime: Date,
  createdAt: {
    type: Date,
    default: Date.now,
  },
})

// 索引
GiftSchema.index({ category: 1, available: 1 })
GiftSchema.index({ price: 1 })
GiftSchema.index({ startTime: 1, endTime: 1 })

export const Gift = mongoose.model<IGift>('Gift', GiftSchema)
